package cn.algorithms_4ed.chapter4;

import cn.algorithms_4ed.base.dataStructure.Bag;
import cn.stdlib.In;

/**
 * #请替换掉这里的东东#
 * <p/>
 * User: root
 * Date: 13-7-10
 * Time: 下午11:04
 */
public class Graph {

    private int v;
    private int e;
    private Bag<Integer>[] adj;

    public Graph(int v) {
        this.v = v;
        this.e = 0;

        adj = (Bag<Integer>[]) new Bag[v];
        for (int i = 0; i < v; i++) {
            adj[v] = new Bag<Integer>();
        }
    }

    public Graph(In in) {
        this(in.readInt());
        int tmp_e = in.readInt();
        for (int i = 0; i < tmp_e; i++) {
            int v = in.readInt();
            int w = in.readInt();
            addEdge(v, w);
        }
    }

    public void addEdge(int v, int w) {
        adj[v].add(w);
        adj[w].add(v);
        e++;
    }

    public Iterable<Integer> adj(int v) {
        return adj[v];
    }

    int v() {
        return v;
    }

    int e() {
        return e;
    }
}
